/*
 * Copyright (C) 拾光分享网 
 * All rights reserved, Designed By www.hiai.top.
 * Email：goodsking@163.com.
 */
package top.hiai._admin.article;

import com.jfinal.aop.Before;
import com.jfinal.kit.Ret;
import com.jfinal.plugin.activerecord.Page;
import top.hiai.common.model.Article;
import top.hiai.common.util.RestTime;
import top.hiai.config.BaseController;
import top.hiai.my.article.MyArticleService;
import top.hiai.my.article.MyArticleValidator;

/**
* @Author www.hiai.top
* @Email  goodsking@163.com
* @Message 更多资源尽在www.hiai.top
* @Introduction 类的介绍:后台文章管理控制器
*/

public class ArticleAdminController extends BaseController{

	ArticleAdminService articleAdminService = ArticleAdminService.me;

	/**
	 * 后台文章管理主页面
	 */
	public void index() {
		Page<Article> articlePage = articleAdminService.paginate(getParaToInt("p", 1),limtCount);
		setAttr("articlePage", articlePage);
		render("articleList.html");
	}
	
	/**
	 * 锁定文章，不用用户查看
	 */
	public void lock() {
		Ret ret = articleAdminService.lock(getParaToInt("id"));
		renderJson(ret);
	}
	
	/**
	 * 解锁文章
	 */
	public void unlock() {
		Ret ret = articleAdminService.unlock(getParaToInt("id"));
		renderJson(ret);
	}
	
	/**
	 * 删除文章
	 */
	public void articleDelete(){
		articleAdminService.articleDelete(getInt("aid"));
		redirect("/admin/article");
	}
	
	/**
	 * 显示文章修改界面
	 */
	public void articleEdit(){
		setAttr("article", articleAdminService.articlefindById(getParaToInt("aid")));
		//遍历分类的列表
		setAttr("commentsList", MyArticleService.me.commentsList());
		render("articleAdminEdit.html");
	}
	
	/**
	 * 后台修改文章保存
	 */
	@Before({MyArticleValidator.class, RestTime.class})
	public void articleUpdate() {
		articleAdminService.articleUpdate(getModel(Article.class));
		renderJson(Ret.ok());
	}
}